#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
struct node
{
    string no;
    int no1;
    int no2;
}a[1005];
int n, m;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].no >> a[i].no1 >> a[i].no2;
    }
    cin >> m;
    int t;
    for (int i = 0; i < m; i++)
    {
        cin >> t;
        for (int j = 0; j < n; j++)
        {
            if (a[j].no1 == t)
            {
                cout << a[j].no << " " << a[j].no2 << endl;
                break;
            }
        }
    }
}